package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.Member
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IJoinVerifyView
import de.baumann.browser.model.NodeModel

class JoinVerifyPresenter : BasePresenter<IJoinVerifyView>() {
    private val nodeModel = NodeModel()

    fun joinVerify() {
        this.nodeModel.joinVerify(view.getApplyId())
                .subscribe(object : OdinObserver<Member>(view) {
                    override fun onSuccess(data: Member?) {
                        if (view != null && data != null) {
                            view.setJvHead(data.avatar)
                            view.setJvHash(data.contribute)
                            view.setJvName(data.userName)
                            view.setJvProportion(data.proportion)
                            view.setJvNodeHash(data.afterContribute)
                            view.setJvTime(data.application_time)
                        }
                    }
                })
    }


    fun joinVerifyAction(status: Int) {
        this.nodeModel.joinVerifyAction(view.getApplyId(), status)
                .subscribe(object : OdinObserver<Any>(view) {
                    override fun onSuccess(data: Any?) {
                        if (view == null) {
                            return
                        }
                        when (status) {
                            1 ->
                                view.verifyPass()
                            2 ->
                                view.verifyRefuse()
                        }
                    }
                })
    }
}